home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / misc / emu / arosdev.lha / AROS / rom / utility / clonetagitems.c < prev    next >
C/C++ Source or Header  |  1997-02-03  |  4KB  |  116 lines

  1. /*
  2.     Copyright (C) 1995-1997 AROS - The Amiga Replacement OS
  3.     $Id: clonetagitems.c,v 1.7 1997/02/03 02:58:31 ldp Exp $
  4.  
  5.     Desc: CloneTagItems()
  6.     Lang: english
  7. */
  8. #include "utility_intern.h"
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13. #include <utility/tagitem.h>
  14. #include <proto/utility.h>
  15.  
  16.         AROS_LH1(struct TagItem *, CloneTagItems,
  17.  
  18. /*  SYNOPSIS */
  19.         AROS_LHA(struct TagItem *, tagList, A0),
  20.  
  21. /*  LOCATION */
  22.         struct UtilityBase *, UtilityBase, 12, Utility)
  23.  
  24. /*  FUNCTION
  25.         Duplicates a TagList. The input TagList can be NULL, in which
  26.         case an empty TagList will be returned.
  27.  
  28.     INPUTS
  29.         tagList     -   The TagList that you want to clone
  30.  
  31.     RESULT
  32.         A TagList which contains a copy of the TagItems contained in the
  33.         original list. The list is cloned so that calling FindTagItem()
  34.         on a tag in the clone will return the same value as that in the
  35.         original list (assuming the original has not been modified).
  36.  
  37.     NOTES
  38.  
  39.     EXAMPLE
  40.         struct TagItem *tagList, *tagListClone;
  41.  
  42.         \* Set up the original taglist tagList *\
  43.  
  44.         tagListClone = CloneTagItems( tagList );
  45.  
  46.         \* Do what you want with your TagList here *\
  47.  
  48.         FreeTagItems( tagListClone );
  49.  
  50.     BUGS
  51.  
  52.     SEE ALSO
  53.         AllocateTagItems(), FreeTagItems(), RefreshTagItemClones()
  54.  
  55.     INTERNALS
  56.  
  57.     HISTORY
  58.         29-10-95    digulla automatically created from
  59.                             utility_lib.fd and clib/utility_protos.h
  60.         11-08-96    iaint   Implemented as AROS function.
  61.         01-09-96    iaint   Updated the docs to give the same warnings
  62.                             as the autodocs.
  63.         05-09-96    iaint   Bit of optimisation (one variable :( )
  64.         23-01-97    iaint   Corrected NULL TagList handling.
  65.  
  66. *****************************************************************************/
  67. {
  68.     AROS_LIBFUNC_INIT
  69.  
  70.     struct TagItem *newList;
  71.     LONG numTags = 1;
  72.  
  73.     /*
  74.         This is rather strange, if we have a NULL input, then we still
  75.         have to allocate a list. This is to circumvent a bug in SID v2,
  76.         which for some unknown reason is the only program I have seen
  77.         that has this problem.
  78.  
  79.         Had to alter RefreshTagItemClones as well.
  80.         However, that is also what the autodoc says...
  81.     */
  82.     if (tagList)
  83.     {
  84.         /*
  85.             We start the counter at 1 since this count will not include the
  86.             TAG_DONE TagItem
  87.  
  88.             newList is used here to save a variable. We don't need to do
  89.             anything to the value of newList afterwards, since AllocateTagitems()
  90.             will take care of setting it to NULL if the allocation fails.
  91.         */
  92.         newList = tagList;
  93.         while (NextTagItem (&newList) != NULL)
  94.             numTags++;
  95.     }
  96.  
  97.     /*
  98.         Then we shall allocate the TagList.
  99.         If we can actually allocate a clone tag list, then we shall copy
  100.         the tag values from one tag to another, the function
  101.         "RefreshTagItemClones()" is used here to help re-use code.
  102.  
  103.         Of course we don't have to worry about the if and only if
  104.         statement, since the original is guaranteed to have not
  105.         been changed since CloneTagItems() :)
  106.     */
  107.  
  108.     if ((newList = AllocateTagItems(numTags)))
  109.         RefreshTagItemClones (newList, tagList);
  110.  
  111.     /* newList == 0 when allocation failed - AllocateTagItems handles this*/
  112.     return newList;
  113.  
  114.     AROS_LIBFUNC_EXIT
  115. } /* CloneTagItems */
  116.